package com.uw.scenic.config.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 在过滤器中存储客户端请求结束的时间戳
 */
@Slf4j
@Component
@SuppressWarnings("all")
public class AccessLogFilter extends  AbstractPreZuulFilter{


    @Override
    protected Object cRun() {
        HttpServletRequest request=context.getRequest();
        Long startTime=(Long)context.get("startTime");
        context.set("startTime",System.currentTimeMillis());
        String uri=request.getRequestURI();
        long duration=System.currentTimeMillis()-startTime;
        log.info("uri:{},duration:{}",uri,duration);
        return  success();
    }

    @Override
    public int filterOrder() {
        return FilterConstants.SEND_RESPONSE_FILTER_ORDER-1;
    }
}
